#ifndef NET_SESSION_H
#define NET_SESSION_H

#define NET_SESSION_BUFFER_MAX 1024

#include "../../../Base/RecursiveLockingMutex.h"
#include "../../../Base/Threaded.h"

#include <boost/asio.hpp>
#include <boost/thread/thread.hpp>

using namespace boost;
using namespace boost::asio;
using asio::ip::tcp;

namespace mp_net
{
	typedef boost::shared_ptr<asio::io_service> shpIoService;
	typedef boost::shared_ptr<io_service::work> shpWork;
	typedef boost::shared_ptr<tcp::socket>		shpSocket;
	using	mp_base::							shpThread;

	class NetSession : 
		public mp_base::RecursiveLockingMutex,
		public mp_base::Threaded
	{
	public:	
		NetSession(shpSocket socket, shpIoService service);
		virtual ~NetSession(){}

		virtual bool Start(){return StartThread();}
		virtual bool Stop(bool wait=false){return StopThread(wait);}

		virtual void ThreadInitialization();
		virtual void ThreadUpdate();
		virtual void ThreadShutdown();

	protected:

		shpIoService	m_ioService;
		shpThread		m_thread;
		shpSocket*		m_sockets;
		unsigned int	m_socketCount;
		char			m_inBuffer[NET_SESSION_BUFFER_MAX];
		char			m_outBuffer[NET_SESSION_BUFFER_MAX];
	};
};

#endif